package com.sunjy.demo1.controller;

import com.sunjy.common.annotation.BeanValid;
import com.sunjy.common.base.BaseController;
import com.sunjy.common.domain.ApiResponseT;
import com.sunjy.common.domain.HeaderEnum;
import com.sunjy.common.exception.ServiceException;
import com.sunjy.demo1.form.UserForm;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Auther: sunjy
 * @Date: 2018/10/18 22:34
 * @Description:
 */
@RestController
@RequestMapping("ex")
public class TestExceptionController extends BaseController {

    @BeanValid
    @PostMapping(value="/test1", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponseT putUser(@Valid @RequestBody UserForm user, BindingResult bind) {

        try {
            int i=1/0;
        } catch (Exception e) {
            throw new ServiceException(HeaderEnum.SYS_MSG);
        }
        return ApiResponseT.success();
    }
}
